package org.wishwork;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.wishwork.api.aftersale.AfterSaleApi;
import org.wishwork.api.allocate.AllocateApi;
import org.wishwork.api.auth.AuthUrlApi;
import org.wishwork.api.base.BaseApi;
import org.wishwork.api.express.ExpressApi;
import org.wishwork.api.inventory.InventoryApi;
import org.wishwork.api.order.OrderApi;
import org.wishwork.api.product.ProductApi;
import org.wishwork.api.purchase.PurchaseApi;
import org.wishwork.api.sign.SignApi;
import org.wishwork.api.stock.in.StockInApi;
import org.wishwork.api.stock.other.OtherInOutApi;
import org.wishwork.api.stock.out.StockOutApi;
import org.wishwork.api.supplier.SupplierApi;
import org.wishwork.api.token.TokenApi;
import org.wishwork.context.Context;
import org.wishwork.context.DefaultContext;

/**
 * @description: 聚水潭 SDK API 服务类
 * @author: WangYX
 * @create: 2022-04-01 15:25
 * @Version: 1.0.0
 **/
public class JSTService {

    private static final Logger log = LoggerFactory.getLogger(JSTService.class);

    public static Context context;

    private final AuthUrlApi authUrlApi;

    private final SignApi signApi;

    private final TokenApi tokenApi;

    private final BaseApi baseApi;

    private final InventoryApi inventoryApi;

    private final PurchaseApi purchaseApi;

    private final SupplierApi supplierApi;

    private final ProductApi productApi;

    private final StockInApi stockInApi;

    private final StockOutApi stockOutApi;

    private final OtherInOutApi otherInOutApi;

    private final AfterSaleApi afterSaleApi;

    private final AllocateApi allocateApi;

    private final ExpressApi expressApi;

    private final OrderApi orderApi;

    public JSTService(JSTProperties jstProperties) {
        log.info("JSTService init!!!");

        context = new DefaultContext(jstProperties);
        this.authUrlApi = new AuthUrlApi(context);
        this.signApi = new SignApi(context);
        this.tokenApi = new TokenApi(context);
        this.baseApi = new BaseApi(context);
        this.inventoryApi = new InventoryApi(context);
        this.purchaseApi = new PurchaseApi(context);
        this.supplierApi = new SupplierApi(context);
        this.productApi = new ProductApi(context);
        this.stockInApi = new StockInApi(context);
        this.stockOutApi = new StockOutApi(context);
        this.otherInOutApi = new OtherInOutApi(context);
        this.afterSaleApi = new AfterSaleApi(context);
        this.allocateApi = new AllocateApi(context);
        this.expressApi = new ExpressApi(context);
        this.orderApi = new OrderApi(context());
    }

    /**
     * 获取上下文
     *
     * @return
     */
    public Context context() {
        return context;
    }

    /**
     * 获取店铺授权的URL
     *
     * @return
     */
    public AuthUrlApi auth() {
        return this.authUrlApi;
    }

    /**
     * 签名验证
     *
     * @return
     */
    public SignApi sign() {
        return this.signApi;
    }

    /**
     * token相关API
     *
     * @return
     */
    public TokenApi token() {
        return this.tokenApi;
    }

    /**
     * 基础Api
     *
     * @return
     */
    public BaseApi base() {
        return this.baseApi;
    }

    /**
     * 库存API
     *
     * @return
     */
    public InventoryApi inventory() {
        return this.inventoryApi;
    }

    /**
     * 采购单API
     *
     * @return
     */
    public PurchaseApi purchase() {
        return this.purchaseApi;
    }

    /**
     * 供应商
     *
     * @return
     */
    public SupplierApi supplier() {
        return this.supplierApi;
    }

    /**
     * 商品
     *
     * @return
     */
    public ProductApi product() {
        return this.productApi;
    }

    /**
     * 入库
     *
     * @return
     */
    public StockInApi stockIn() {
        return this.stockInApi;
    }

    /**
     * 出库
     *
     * @return
     */
    public StockOutApi stockOut() {
        return this.stockOutApi;
    }

    /**
     * 其他出入库
     *
     * @return
     */
    public OtherInOutApi otherInOut() {
        return this.otherInOutApi;
    }

    /**
     * 售后Api
     *
     * @return
     */
    public AfterSaleApi afterSale() {
        return this.afterSaleApi;
    }

    /**
     * 调拨API
     *
     * @return
     */
    public AllocateApi allocate() {
        return this.allocateApi;
    }

    /**
     * 物流API
     *
     * @return
     */
    public ExpressApi express() {
        return this.expressApi;
    }

    /**
     * 订单API
     *
     * @return
     */
    public OrderApi order() {
        return this.orderApi;
    }
}
